//
//  PS_DummyStatusView.m
//  PolicySystem
//
//  Created by 丹丹 on 2018/11/3.
//  Copyright © 2018年 xuezi. All rights reserved.
//

#import "PS_DummyStatusView.h"

@implementation PS_DummyStatusView

- (instancetype)initWithFrame:(CGRect)frame andImageName:(NSString *)imageName andDummyLabelText:(NSString *)str
{
    if (self == [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor whiteColor];
        
        UIImage * image = [UIImage imageNamed:imageName];
        
        float x = (SCREEN_WIDTH - image.size.width)/2;
        float y;
        
        if ([imageName isEqualToString:@"kong1"]) {
            
            y = (frame.size.height-image.size.height)/2 - 100;
            
        }else{
            
            y = (frame.size.height-image.size.height)/2;
        }
        
        float h = image.size.height;
        float w = image.size.width;
        UIImageView * image_view = [[UIImageView alloc]initWithFrame:CGRectMake(x, y, w, h)];
        image_view.image = image;
        [self addSubview:image_view];
        
        UILabel * lab = [[UILabel alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(image_view.frame)+10, SCREEN_WIDTH, 20)];
        lab.font = [UIFont systemFontOfSize:15];
        lab.textColor = RGBCOLOR(151, 151, 151);
        lab.text = str;
        lab.textAlignment = NSTextAlignmentCenter;
        [self addSubview:lab];
        
        UIButton * refreshButton = [UIButton buttonWithType:UIButtonTypeCustom];
                                    
        refreshButton.frame = CGRectMake(30, CGRectGetMaxY(lab.frame)+50, SCREEN_WIDTH - 60, 50);
        refreshButton.layer.cornerRadius = 15;
        refreshButton.layer.borderWidth = 1;
        refreshButton.layer.borderColor = RGBCOLOR(238, 114, 111).CGColor;
        [refreshButton setTitle:@"重新加载" forState:UIControlStateNormal];
        [refreshButton setTitleColor:RGBCOLOR(238, 114, 111) forState:UIControlStateNormal];
        [refreshButton addTarget:self action:@selector(reloadRequestData:) forControlEvents:UIControlEventTouchUpInside];
        
        if ([imageName isEqualToString:@"kong1"]) {
            
            [self addSubview:refreshButton];
        }
       
                                    

    }
    
    return self;
}

- (void)reloadRequestData:(UIButton *)sender{
    
    if ([_delegate respondsToSelector:@selector(reloadViewData)]) {

        [_delegate reloadViewData];
    }
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

@end
